import java.util.*;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-12-31
 * Time:11:09
 */
public class TestDemo {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("国民女神","兵姐姐");
        map.put("国民男神","兵哥哥");
        System.out.println(map);
        map.put("悟净","沙僧");
        map.put("孔明","诸葛亮");
        //map.put("孔明","诸葛亮1");//key可以重复,但是只储存了最后更新的value值,value值是可以重复的
        System.out.println(map);//map/put存储元素的顺序是无序的,是按照hash表达式排序的
        String s = map.get("国民男神");
        System.out.println(s);
        String s1 = map.getOrDefault("帅哥","谢邦");//如果没有这个key,则这key值对应的value值是defaultvalue值
        System.out.println(s1);
        System.out.println(map.size());//map的大小

        System.out.println("====================");
        System.out.println(map.containsKey("帅哥"));//是否包含指定的key值
        System.out.println(map.containsValue("诸葛亮"));//是否包含指定的value值


        Set<Map.Entry<String, String>> entrySet = map.entrySet();//把键值对组合放入set集合中

        for (Map.Entry<String,String> entry: entrySet) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
        //

    }
    public static void main2(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("hello");
        collection.add("hello1");
        collection.add("hello2");//存放在数组的最后的
        System.out.println(collection.size());
        System.out.println(collection.isEmpty());//判断集合是否为空
        System.out.println(collection);
        Object[] objects = collection.toArray();
        System.out.println(Arrays.toString(objects));
//object[]数组不能装换为其他类型的数组,在Java中数组不能进行整体的类型转换.
        collection.remove("hello1");//删除指定元素
        System.out.println(collection);
        collection.clear();//删除集合中的所有元素
        System.out.println(collection);
        System.out.println(collection.size());//集合中元素的个数
        System.out.println(collection.isEmpty());
//        Collection collection1 = new ArrayList();
//        collection1.add(1);
//        collection1.add("hello");//不建议这样写
    }
    public static void main1(String[] args) {
        Collection<String> collection = new ArrayList<>();
        Collection<String> collection1 = new LinkedList<>();
        Collection<String> collection2 = new Stack<>();

        ArrayList<String>/*指定的类型*/ arrayList = new ArrayList<>();//只能增加字符串类型(顺序表)//泛型
        arrayList.add("hello");
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        ArrayList<Double> arrayList2 = new ArrayList<>();


        List<String> arrayList4 = new ArrayList<>();

     }
}
